<?php

use app\assets\BackendAsset as Asset;
use \app\models\tableModel\AdminRoleModel;

?>
<el-container class="index-wrapper">
    <el-header class="top-wrapper bg-white" :class="getTopClass" height="auto" ref="mainScrollShadow">
        <el-row :inline="true" class="button-container">
            <el-col :xs="12" :sm="12" :md="12" :lg="5">
                <el-breadcrumb separator="/">
                    <el-breadcrumb-item>
                        <a @click="goToIndex"><i class="el-icon-location-outline"></i>&nbsp;首页</a>
                    </el-breadcrumb-item>
                    <el-breadcrumb-item @dblclick.native="window.open(window.location.href)">
                        权限管理
                    </el-breadcrumb-item>
                </el-breadcrumb>
            </el-col>
            <el-col :xs="12" :sm="12" :md="12" :lg="19" class="text-right">
                <?php if (AdminRoleModel::checkAuth('AdminMenu', 'cache')) { ?>
                <el-button class="mr-10" size="mini" type="danger"
                           @click.native="showClearDialog()">
                    刷新角色缓存
                </el-button>
                <?php } ?>
                <?php if (AdminRoleModel::checkAuth('reload')) { ?>
                <el-button class="" size="mini" type="danger" @click.native="reload()">
                    刷新权限
                </el-button>
                <?php } ?>
                <el-dropdown size="mini">
                    <el-button type="primary" size="mini">
                        更多操作
                        <i class="el-icon-arrow-down el-icon--right"></i>
                    </el-button>
                    <el-dropdown-menu slot="dropdown">
                        <?php if (AdminRoleModel::checkAuth('open')) { ?>
                        <el-dropdown-item @click.native="openItem(null)"
                                          size="mini" :divided="true">
                            批量恢复
                        </el-dropdown-item>
                        <?php } ?>
                        <?php if (AdminRoleModel::checkAuth('disabled')) { ?>
                        <el-dropdown-item @click.native="disabledItem(null)"
                                          size="mini">
                            批量禁用
                        </el-dropdown-item>
                        <?php } ?>
                    </el-dropdown-menu>
                </el-dropdown>
            </el-col>
        </el-row>
    </el-header>
    <el-main class="content-wrapper transits">
        <div class="p-10" style="display: none;">
            <!-- 提醒 START -->
            <div class="tip no-mt">
                <el-collapse v-model="setting.activeNotice" accordion>
                    <el-collapse-item>
                        <template slot="title">
                            <i class="el-icon el-icon-info"></i>
                            &nbsp;&nbsp;
                            <span class="title">
                                温馨提示
                            </span>
                        </template>
                        <div class="content">
                            <p>
                                1、菜单最多添加到3级，4及上不展示！
                            </p>
                        </div>
                    </el-collapse-item>
                </el-collapse>
            </div>
            <!-- 提醒 END -->
        </div>
        <!-- 查询 START -->
        <?= $this->render('../common/search.php', [
            'groupFields'      => 'searchForm.group',
            'groupOtherFields' => 'searchForm.groupOther',
            'baseFields'       => 'searchForm.base',
            'moreFields'       => 'searchForm.more',
            'export'           => 'searchForm.value',
            'submit'           => 'getList'
        ]); ?>
        <div class="pt-10"></div>
        <!-- 查询 START -->
        <el-row :gutter="30" class="bottom-wrapper">
            <el-col :span="9">
                <div class="am-panel-wrapper">
                    <div class="am-panel-hd">
                        <el-row :gutter="0">
                            <el-col :span="12">
                                <el-tooltip class="item" effect="light" placement="top-start">
                                    <div slot="content">
                                        <span class="title-txt">未取得权限</span>
                                        <span v-text="'(' + haveNotAuth.count + '个)'"
                                              class="count-txt font-third"></span>
                                    </div>
                                    <div class="text-more-ellipsis">
                                        <span class="title-txt">未取得权限</span>
                                        <span v-text="'(' + haveNotAuth.count + '个)'"
                                              class="count-txt font-third"></span>
                                    </div>
                                </el-tooltip>
                            </el-col>
                            <el-col :span="6" class="text-right">
                                <el-button @click="checkCancelAll(true, 'notHaveTreeDemo')"
                                           type="text" size="mini">
                                    全选
                                </el-button>
                                <el-button @click="checkCancelAll(false, 'notHaveTreeDemo')"
                                           type="text" size="mini">
                                    取消
                                </el-button>
                            </el-col>
                            <el-col :span="6" class="text-right">
                                <el-button @click="openCloseAll(true, 'notHaveTreeDemo')"
                                           type="text" size="mini">
                                    全开
                                </el-button>
                                <el-button @click="openCloseAll(false, 'notHaveTreeDemo')"
                                           type="text" size="mini">
                                    全关
                                </el-button>
                            </el-col>
                        </el-row>
                    </div>
                    <div class="am-panel-bd am-scrollable-vertical" :style="transferStyle">
                        <el-scrollbar class="main-scroller" style="height: 100%;width: 100%;">
                            <ul id="notHaveTreeDemo" class="ztree"></ul>
                        </el-scrollbar>
                    </div>
                </div>
            </el-col>
            <el-col :span="6" class="text-center">
                <div class="center-role-wrapper">
                    <el-select v-model="roleId" @change="getList()" class="form-item">
                        <el-option label="请选择角色" :value="null"></el-option>
                        <el-option v-for="(item, key) in roleList" :key="key"
                                   :label="item.name" :value="item.id">
                        </el-option>
                    </el-select>
                </div>
                <div class="center-do-wrapper" :style="transButtonStyle">
                    <el-button type="primary" icon="el-icon-right" plain @click="toHave">
                    </el-button>
                    <el-button type="primary" icon="el-icon-back" plain @click="toHaveNot">
                    </el-button>
                </div>
                <div class="center-do-wrapper">
                    <?php if (AdminRoleModel::checkAuth('saveAuth')) { ?>
                    <el-button type="primary" size="medium" @click="saveAuth">
                        保存
                    </el-button>
                    <?php } ?>
                </div>
            </el-col>
            <el-col :span="9">
                <div class="am-panel-wrapper">
                    <div class="am-panel-hd">
                        <el-row :gutter="0">
                            <el-col :span="12" class="text-more-ellipsis">
                                <el-tooltip class="item" effect="light" placement="top-start">
                                    <div slot="content">
                                        <span class="title-txt">已取得权限</span>
                                        <span v-text="'(' + haveAuth.count + '个)'"
                                              class="count-txt font-third"></span>
                                    </div>
                                    <div class="text-more-ellipsis">
                                        <span class="title-txt">已取得权限</span>
                                        <span v-text="'(' + haveAuth.count + '个)'"
                                              class="count-txt font-third"></span>
                                    </div>
                                </el-tooltip>
                            </el-col>
                            <el-col :span="6" class="text-right text-more-ellipsis">
                                <el-button type="text" size="mini"
                                           @click="checkCancelAll(true, 'haveTreeDemo')">
                                    全选
                                </el-button>
                                <el-button type="text" size="mini"
                                           @click="checkCancelAll(false, 'haveTreeDemo')">
                                    取消
                                </el-button>
                            </el-col>
                            <el-col :span="6" class="text-right text-more-ellipsis">
                                <el-button type="text" size="mini"
                                           @click="openCloseAll(true, 'haveTreeDemo')">
                                    全开
                                </el-button>
                                <el-button type="text" size="mini"
                                           @click="openCloseAll(false, 'haveTreeDemo')">
                                    全关
                                </el-button>
                            </el-col>
                        </el-row>
                    </div>
                    <div class="am-panel-bd am-scrollable-vertical" :style="transferStyle">
                        <el-scrollbar class="main-scroller" style="height: 100%;width: 100%;">
                            <ul id="haveTreeDemo" class="ztree"></ul>
                        </el-scrollbar>
                    </div>
                </div>
            </el-col>
        </el-row>
    </el-main>
</el-container>

<!-- 刷新缓存 -->
<?= $this->render('../common/clear-cache.php', [
    'cacheUrl' => ['adminMenu']
]);?>
<!-- 刷新缓存 -->
<?= Asset::addCss($this, '/plugin/ztree/css/zTreeStyle.css'); ?>
<?= Asset::addCss($this, '/css/backend/admin-auth-index.css'); ?>
<?= Asset::addScript($this, '/js/backend/admin-auth-index.js'); ?>
<?= Asset::addScript($this, '/plugin/ztree/js/jquery.ztree.core.min.js'); ?>
<?= Asset::addScript($this, '/plugin/ztree/js/jquery.ztree.exedit.js'); ?>
<?= Asset::addScript($this, '/plugin/ztree/js/jquery.ztree.excheck.js'); ?>
<?= Asset::addScript($this, '/plugin/ztree/js/jquery.ztree.exhide.js'); ?>
<?= Asset::addScript($this, '/plugin/ztree/js/jquery.ztree.fuzzysearch.js'); ?>
<?php

// 重命名权限
$rename = intval(AdminRoleModel::checkAuth('rename'));
// 禁用权限
$disabled = intval(AdminRoleModel::checkAuth('disabled'));
// 开启权限
$open = intval(AdminRoleModel::checkAuth('open'));
$this->registerJs('
    instance = new app({
        rename: ' . $rename . ',
        disabled: '. $disabled . ',
        open: '. $open . '
    });
');
?>
